﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'DasIdeen_User_GetUserWithAdministratorAuthorization')
	BEGIN
		DROP  Procedure  DasIdeen_User_GetUserWithAdministratorAuthorization
	END

GO

CREATE PROCEDURE [DasIdeen_User_GetUserWithAdministratorAuthorization]
-- =============================================
-- Author:		<Sagar s.k>
-- Create date: <03/04/2015>
-- Description:	<DasIdeen_User_GetUserWithAdministratorAuthorization>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				@UserKey int
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

	SELECT   TOP 1  
			[User].[UserKey],
			[User].[UserLoginID],
			[User].[UserPassword],
			[User].[UserFirstName],
			[User].[UserLastName],
			[User].[UserPrimaryEmailID],
			[User].[UserVerificationCode],
			[User].[UserIsVerified],
			[User].[Sys_DateOfCreation],
			[User].[Sys_DateOfModification],
			[User].[Sys_CreatedByID],
			[User].[Sys_ModifiedByID],
			[User].[Sys_DeleteType],
			[User].[Sys_IsDeleted],
			[User].[Sys_OrganizationID],
			[User].[Sys_InitialPrimaryKeys],
			[User].[Sys_WorkstationName]
FROM        [Sys_RoleMaster] RIGHT OUTER JOIN [UserRole] 
ON          [Sys_RoleMaster].[RoleKey] = [UserRole].[UserRoleKey] RIGHT OUTER JOIN [User] 
ON          [UserRole].[UserKey] = [User].[UserKey]

WHERE		(
				([User].[UserKey] = @UserKey)
			) 
			AND 
			(
				([Sys_RoleMaster].[RoleCode] = 'SYSSPRADM') OR
				([Sys_RoleMaster].[RoleCode] = 'SYSADMIN')
			)
END
GO
